﻿using Chloe;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using WebApiOrm.Domain;

namespace WebApiOrm.Provider.Chloe
{
    sealed class ChloeOrmProvider : IOrmProvider
    {
        private readonly IDbContext db;

        public Version? Version => db.GetType().Assembly.GetName().Version;

        public ChloeOrmProvider(IDbContext db)
        {
            this.db = db;
        }

        public async Task<bool> AddSysUserAsync(SysUser user)
        {
            await db.InsertAsync(user);
            return true;
        }

        public async Task<IList<SysUser>> QuerySysUsersAsync(Expression<Func<SysUser, bool>> predicate, int skip, int take)
        {
            return await db.Query<SysUser>().Where(predicate).OrderBy(item => item.Id).Skip(skip).Take(take).ToListAsync();
        }
    }
}